package love.yuanmengrobot.attendancesystem.servlet;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/20 21:18
 */

import love.yuanmengrobot.attendancesystem.dao.MemberDao;

import java.io.IOException;
import java.io.PrintWriter;

public class RegisterServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("id");
        String paw = request.getParameter("paw");
        String permission = request.getParameter("permission");
        String name = request.getParameter("name");
        System.out.println("结果："+id+paw+name+permission);
        MemberDao memberDao = new MemberDao();
        PrintWriter pw = response.getWriter();
        int su = 0;
        if ("0".equals(permission)) {//教师进行注册
            su = memberDao.insertTeacher(id, paw,name);
        } else {//学生进行注册
            su = memberDao.insertStudent(id, paw,name);
        }
        if (su == 1)  pw.print("{\"meg\":\"注册成功\"}");
        else  pw.print("{\"meg\":\"注册失败\"}");
        pw.flush();
        pw.close();
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String name = request.getParameter("id");
        String age = request.getParameter("paw");
        PrintWriter pw = response.getWriter();
        pw.print("您使用get方式请求该Servlet。<br />" + "name = " + name + ",age = " + age);
        pw.flush();
        pw.close();
    }
}
